package com.ptu.controller.admin;

import com.ptu.server.SeckillOrderServer;
import com.ptu.util.PageResult;
import com.ptu.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSeckillOrderController")
@RequestMapping("/admin/seckillOrder")
@Tag(name = "秒杀订单模块")
public class SeckillOrderController {

    @Autowired
    private SeckillOrderServer seckillOrderServer;

    @Operation(summary = "获取秒杀订单列表")
    @GetMapping("/list")
    public Result<PageResult> list(Integer pageNum, Integer pageSize) {
        System.out.println("分页订单");
        PageResult pageResult = seckillOrderServer.getList(pageNum, pageSize);
        return Result.success(pageResult);
    }

    @Operation(summary = "秒杀订单发货")
    @PostMapping("/deliver/{id}")
    public Result<Void> deliver(@PathVariable Long id) {
        seckillOrderServer.deliver(id);
        return Result.success();
    }

    @Operation(summary = "秒杀订单退款")
    @PostMapping("/refund/{id}")
    public Result<Void> refund(@PathVariable Long id) {
        seckillOrderServer.adminRefund(id);
        return Result.success();
    }

    @Operation(summary = "取消秒杀订单")
    @PostMapping("/cancel/{id}")
    public Result<Void> cancel(@PathVariable Long id) {
        seckillOrderServer.cancel(id);
        return Result.success();
    }

}
